package net.borlis.sample.services.facade.ws.response;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * @author alex@borlis.net on 27.05.2014.
 */
@XmlRootElement
public class CountryResponse extends BaseCountryResponse {

    @XmlElement
    private CurrencyResponse currency;

    public CountryResponse() {
        super();
    }

    public CountryResponse(Long id, String code, String name, CurrencyResponse currency) {
        super(id, code, name);
        this.currency = currency;
    }

    public CurrencyResponse getCurrency() {
        return currency;
    }

    @Override
    public boolean equals(Object obj) {
        if (! super.equals(obj)) {
            return false;
        }
        if (obj instanceof CountryResponse) {
            CountryResponse other = (CountryResponse) obj;
            EqualsBuilder builder = new EqualsBuilder();
            builder.append(getCurrency(), other.getCurrency());
            return builder.isEquals();
        }
        return false;
    }

    @Override
    public int hashCode() {
        HashCodeBuilder builder = new HashCodeBuilder();
        builder.append(getId());
        builder.append(getCode());
        builder.append(getName());
        builder.append(getCurrency());
        return builder.toHashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                append("id", getId()).
                append("code", getCode()).
                append("name", getName()).
                append("currency", getCurrency()).
                toString();
    }
}
